//
//  ViewController.swift
//  Matting
//  Created by JoyWT on 2022/3/4
//  
    

import UIKit
import EasyPeasy
import TableKit
import Then
struct trysModel {
    var title = ""
    var VCClass: BaseViewController.Type?
}
class ViewController: UIViewController {
    
    let tableview = UITableView(frame: .zero, style: .plain)
    lazy var tableDirector = TableDirector(tableView: tableview)
    lazy var tableSection = TableSection(headerView: UIView(), footerView: UIView(), rows: [])
    let dataSource = [ trysModel(title: "Mask", VCClass: MaskViewController.self) ,
                       trysModel(title: "Trimap", VCClass: TriMapViewController.self),
                       trysModel(title: "Alpha", VCClass: AlphaViewController.self),
                       trysModel(title: "移除背景", VCClass: RmoveBgViewController.self),
                       trysModel(title: "Mask-移除背景", VCClass: MaskRmbgViewController.self),
                       trysModel(title: "替换背景", VCClass: ChangeBgViewController.self) ,
                       trysModel(title: "模糊背景", VCClass: BlurViewController.self)]
    override func viewDidLoad() {
        super.viewDidLoad()
        title = "Matting"
        // Do any additional setup after loading the view.
        view.addSubview(tableview)
        tableview.easy.layout(Edges())
        configTable()
    }
    private lazy var  rowAction = TableRowAction<TableViewCell>(.click){
        [weak self] options in
        let indexPath = options.indexPath
        let item = options.item
        if let vcClass = item.VCClass {
            let vc = vcClass.init()
            vc.titleText = item.title
            self?.navigationController?.pushViewController(vc, animated: true)
        }else {
            print("VCClass 不能为 nil/null")
        }
    }
    func configTable(){
        var rows = [Row]()
        for item in dataSource {
            let row = TableRow<TableViewCell>(item:item).on(rowAction)
            rows.append(row)
        }
        tableSection.append(rows: rows)
        tableDirector += tableSection
        tableDirector.reload()
    }


}

